home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 5 code / Scanning from ProDOS / Dev.Sampledbl.aii < prev    next >
Encoding:
Text File  |  1990-11-07  |  25.0 KB  |  1,061 lines  |  [TEXT/MPS ]

  1.  
  2. ;*******************************************************
  3. ;
  4. ;    Develop Code Samples.
  5. ;
  6. ;    Written by Matt Gulick.        Started October 16,1990
  7. ;
  8. ;*******************************************************
  9.  
  10. ;*******************************************************
  11. ;
  12. ;    This file contains the code samples that are used in
  13. ;    the Scanning From ProDOS article in DEVELOP.  These
  14. ;    code segments may be used freely by anyone.  All
  15. ;    code in this file assumes that we are running in an
  16. ;    8 bit Apple IIe.
  17. ;
  18. ;*******************************************************
  19.  
  20. ;*******************************************************
  21. ;
  22. ;    Revision History:
  23. ;
  24. ;*******************************************************
  25.  
  26. ;    Oct  16, 1990    File started.
  27. ;
  28.  
  29.             STRING        PASCAL
  30.             BLANKS        OFF
  31.             PAGESIZE    70
  32.             PRINT        NOGEN
  33.             PRINT        NOMDIR
  34.             MACHINE        M65C02
  35.  
  36.             EJECT
  37.             
  38. ;*******************************************************
  39. ;
  40. ;    CODE SAMPLE #1
  41. ;
  42. ;    This first code segment walks the slots starting at
  43. ;    slot 7, looking first for a card of any kind.  Once
  44. ;    found, we check the ID bytes for a Smartport card.
  45. ;    Once found we check the ID Type byte to see if it is
  46. ;    a SCSI Card.  If it passes all these tests, we then
  47. ;    issue a Device $00 Status $00 call to further ensure
  48. ;    that this is the Apple High-Speed SCSI Card.
  49. ;
  50. ;*******************************************************
  51.  
  52.                                 ;
  53.                                 ; The following are Equates
  54.                                 ; that will bee used in all
  55.                                 ; the Sample Code Segments
  56.                                 ; that follow.
  57.                                 ;
  58. rqst_cnt    equ        75
  59.  
  60. slot_7        equ        $C7
  61. slot_1        equ        $C1
  62.  
  63. My_ZPage    equ        $42
  64.  
  65. KBD            equ        $C000        ;Keyboard
  66. CLR80COL    equ        $C000        ;Disable 80_column store
  67. SET80COL    equ        $C001        ;Enable 80_column store
  68. WRMAINRAM    equ        $C004        ;Write to Main 48k
  69. WRCARDRAM    equ        $C005        ;Write to Alternate 48k
  70. CLR80VID    equ        $C00C        ;Disable 80-column hardware
  71. SET80VID    equ        $C00D        ;Enable 80-column hardware
  72. KBD_STRB    equ        $C010        ;Keyboard Strobe
  73. RD80COL        equ        $C018        ;Read 80 Col. Mode
  74. RDTEXT        equ        $C01A        ;Read Text Mode
  75. RDMIX        equ        $C01B        ;Read Mix Mode
  76. RDPAGE2        equ        $C01C        ;Read Page 2 setting
  77. RDHIRES        equ        $C01D        ;Read HiRes setting
  78. RD80VID        equ        $C01F        ;Read 80 Col. Mode
  79. TXTCLR        equ        $C050        ;Clear Text Mode
  80. TXTSET        equ        $C051        ;Set Text Mode
  81. MIXCLR        equ        $C052        ;Clear Mixed Mode
  82. MIXSET        equ        $C053        ;Set Mixed Mode
  83. TXTPAGE1    equ        $C054        ;Set Text Page 1
  84. TXTPAGE2    equ        $C055        ;Set Text page 2
  85. LORES        equ        $C056        ;Set LoRes Graphics
  86. HIRES        equ        $C057        ;Set HiRes Graphics
  87. CLRAN3        equ        $C05E        ;Clear annunciator 3
  88. SETAN3        equ        $C05F        ;Set annunciator 3
  89.  
  90. ESC            equ        $9B            ;High bit set ASCII ESC Key
  91.  
  92. Blk_sig1    equ        $01
  93. Blk_sig2    equ        $03
  94. Blk_sig3    equ        $05
  95. SPort_sig    equ        $07
  96. SPort_ID    equ        $FB
  97.  
  98. Ext_SPort    equ        %10000000    ;Bit 7
  99. SCSI        equ        %00000010    ;Bit 2
  100.  
  101. No_Err        equ        $00
  102. IO_Err        equ        $27
  103. No_dev        equ        $28
  104.  
  105. ;*******************************************************
  106.  
  107.             EXPORT    P8_Scanner
  108. P8_Scanner    PROC
  109.                                 ;
  110.                                 ; Main Code Segment.
  111.                                 ;
  112.  
  113.             jsr        find_card
  114.             jsr        find_scanr
  115.             jsr        htone_filter
  116.             jsr        def_window
  117.             jsr        start_scan
  118.             jsr        get_data
  119.             jsr        display
  120.             bcc        P8_Scanner
  121.             rts
  122.  
  123. ;*******************************************************
  124. ;
  125. ;    CODE SAMPLE #1
  126. ;
  127. ;    This first code segment walks the slots starting at
  128. ;    slot 7, looking first for a card of any kind.  Once
  129. ;    found, we check the ID bytes for a Smartport card.
  130. ;    Once found we check the ID Type byte to see if it is
  131. ;    a SCSI Card.  If it passes all these tests, we then
  132. ;    issue a Device $00 Status $00 call to further ensure
  133. ;    that this is the Apple High-Speed SCSI Card.
  134. ;
  135. ;*******************************************************
  136.  
  137. find_card
  138.                                 ;
  139.                                 ; Save the current Zero
  140.                                 ; Page values before
  141.                                 ; using them.
  142.                                 ;
  143.             lda        <My_ZPage
  144.             pha
  145.             lda        <My_ZPage+1
  146.             pha
  147.                                 ;
  148.                                 ; Start at Slot 7.
  149.                                 ;
  150.             lda        #slot_7
  151.             sta        <My_ZPage+1    ;Zero Page
  152.             sta        slot+1        ;For Safe keeping
  153.             stz        <My_ZPage
  154.             stz        slot
  155.                                 ;
  156.                                 ; Is it a Smartport Card?
  157.                                 ;
  158. @chk_smart    ldy        #Blk_sig1
  159.             lda        (My_ZPage),y;Block_device Signature Byte
  160.             cmp        #$20        ;#1 = $20
  161.             bne        @next_slot
  162.  
  163.             ldy        #Blk_sig2
  164.             lda        (My_ZPage),y;Block_device Signature Byte
  165.             bne        @next_slot    ;#2 = $00
  166.  
  167.             ldy        #Blk_sig3
  168.             lda        (My_ZPage),y;Block_device Signature Byte
  169.             cmp        #$03        ;#3 = $03
  170.             bne        @next_slot
  171.  
  172.             ldy        #SPort_sig
  173.             lda        (My_ZPage),y;SmartPort Signature Byte
  174.             bne        @next_slot    ;#1 = $00
  175.                                 ;
  176.                                 ; We have a Smartport
  177.                                 ; Device.  Is it SCSI with
  178.                                 ; Extended SmartPort?
  179.                                 ;
  180.             ldy        #SPort_ID
  181.             lda        (My_ZPage),y
  182.             and        #Ext_SPort+\
  183.                     SCSI
  184.             cmp        #Ext_SPort+\
  185.                     SCSI
  186.             bne        @next_slot
  187.                                 ;
  188.                                 ; Is it an Apple High-
  189.                                 ; Speed SCSI Card?
  190.                                 ;
  191.             jsr        is_it_appl
  192.             bcc        @exit
  193.                                 ;
  194.                                 ; Check the Next Slot.
  195.                                 ;
  196. @next_slot    lda        <My_ZPage+1
  197.             dec        a
  198.             sta        <My_ZPage+1
  199.             sta        slot+1
  200.             cmp        #slot_1
  201.             bge        @chk_smart
  202.             lda        #No_dev        ;No Device Error
  203.                                 ;
  204.                                 ; Clean Exit
  205.                                 ;
  206. @exit        tax
  207.             pla
  208.             sta        <My_ZPage+1
  209.             pla
  210.             sta        <My_ZPage
  211.             txa
  212.  
  213.             cmp        #$01        ;Set Carry if Non-Zero
  214.             rts
  215.                                 ;
  216.                                 ; This routine determines
  217.                                 ; if the card is the new
  218.                                 ; High-Speed SCSI Card.
  219.                                 ;
  220. is_it_appl    ldy        #$ff
  221.             lda        (My_ZPage),y
  222.             clc
  223.             adc        #$03        ;Set Smartport Entry Address
  224.             sta        card_ntry
  225.  
  226.             lda        <My_ZPage+1
  227.             sta        card_ntry+1
  228.  
  229.             jsr        call_card
  230.             dc.b    $00            ;Status Call Command Number
  231.             dc.w    stat_list1
  232.                                 ;
  233.                                 ; Check the Results
  234.                                 ;
  235.             lda        stat_data+2    ;Low Byte of Vendor ID
  236.             cmp        #$01        ;Must be $01
  237.             bne        @non_apple
  238.  
  239.             lda        stat_data+3    ;High Byte of Vendor ID
  240.             bne        @non_apple    ;Must be $00
  241.  
  242.             lda        stat_data+4    ;Low Byte of Version
  243.             bne        @non_apple    ;Should be Null
  244.  
  245.             lda        stat_data+5    ;High Byte of Version
  246.             bne        @non_apple    ;Should be Null
  247.  
  248.             clc                    ;Acc. 0 by previous LDA
  249.             bra        @done
  250.  
  251. @non_apple    lda        #No_dev        ;Device not found.
  252.             sec
  253.                                 ;
  254.                                 ; Restore ZPage
  255.                                 ;
  256. @done        pha
  257.             php
  258.             lda        slot
  259.             sta        <My_ZPage
  260.             lda        slot+1
  261.             sta        <My_ZPage+1
  262.             plp
  263.             pla
  264.             rts
  265.  
  266. slot        dc.w    $0000
  267.  
  268. ;*******************************************************
  269.  
  270. call_card    jmp        (card_ntry)
  271.  
  272. card_ntry    dc.w    $0000
  273.  
  274. ;*******************************************************
  275.  
  276. stat_list1    dc.b    $03            ;PCount = 3
  277.             dc.b    $00            ;Device = Card
  278.             dc.w    stat_data    ;Data returned here
  279.             dc.b    $00            ;Get Host Status Call
  280.  
  281. ;*******************************************************
  282.  
  283. stat_data    dcb.b    64,0        ;Our Buffer.
  284.  
  285. ;*******************************************************
  286. ;
  287. ;    CODE SAMPLE #2
  288. ;
  289. ;    This code segment walks the unit numbers from the
  290. ;    SCSI Card starting at unit 2 and going to unit 0 to
  291. ;    get the actual unit number count.  Once this is
  292. ;    done, we start at unit 1 and walk forward until we
  293. ;    find the scanner.
  294. ;
  295. ;*******************************************************
  296.  
  297. find_scanr
  298.                                 ;
  299.                                 ; First we issue a
  300.                                 ; Status call to device
  301.                                 ; number 2.  This will
  302.                                 ; force the card to
  303.                                 ; build its tables if it
  304.                                 ; has not yet done so.
  305.                                 ;
  306.             lda        #$02
  307.             sta        dev_num2
  308.             stz        stat_code2
  309.  
  310.             jsr        call_card
  311.             dc.b    $00            ;Status Call Command Number
  312.             dc.w    stat_list2
  313.             bcs        @error
  314.                                 ;
  315.                                 ; Now call Unit 0 to
  316.                                 ; find out the total
  317.                                 ; device count.
  318.                                 ;
  319.             stz        dev_num2
  320.             jsr        call_card
  321.             dc.b    $00            ;Status Call Command Number
  322.             dc.w    stat_list2
  323.             bcs        @error
  324.  
  325.             lda        stat_data2    ;Get the Total Device
  326.             sta        dev_count    ;Count
  327.  
  328.             lda        #$03        ;Set up for DIB Status
  329.             sta        stat_code2    ;Calls
  330.  
  331. @loop        lda        dev_num2    ;First time we increment
  332.             cmp        dev_count    ;a zero giving a device
  333.             bge        @error        ;number of 1.
  334.  
  335.             inc        dev_num2
  336.             jsr        call_card
  337.             dc.b    $00            ;Status Call Command Number
  338.             dc.w    stat_list2
  339.             bcs        @error
  340.  
  341.             lda        d_type
  342.             cmp        #$08        ;Is it Type = Scanner?
  343.             bne        @loop        ;No.
  344.  
  345.             lda        d_stype
  346.             cmp        #$A0        ;Subtype = $A0?
  347.             bne        @loop        ;No
  348.                                 ;
  349.                                 ; Scan string is a Pascal
  350.                                 ; String.  A length byte
  351.                                 ; followed by ASCII.  We
  352.                                 ; want to make sure they
  353.                                 ; are both the same length
  354.                                 ; as well as the same text.
  355.                                 ;
  356.             ldx        id_str_len
  357. @str_loop    lda        id_str_len,x
  358.             cmp        scan_str,x
  359.             bne        @loop
  360.             dex
  361.             bne        @str_loop
  362.  
  363.             lda        dev_num2    ;We have our Scanner
  364.             sta        scan_dnum
  365.             lda        #No_Err
  366.             clc
  367.             rts
  368.  
  369. @error        lda        #No_dev        ;Device not found.
  370.             sec
  371.             rts
  372.  
  373. ;*******************************************************
  374.  
  375. scan_str    dc.b    'APPLE   SCANNER '    ;4 Spaces between
  376.                                         ;1 Sace after
  377. dev_count    dc.b    $00
  378.  
  379. ;*******************************************************
  380.  
  381. scan_dnum    dc.b    $00            ;Scanner Device Number
  382.  
  383. ;*******************************************************
  384.  
  385. stat_list2    dc.b    $03            ;PCount = 3
  386. dev_num2    dc.b    $00            ;Device number
  387.             dc.w    stat_data2    ;Data returned here
  388. stat_code2    dc.b    $00            ;Status Code
  389.  
  390. ;*******************************************************
  391.  
  392. stat_data2                        ;Our Buffer. Used over.
  393. d_stat        dc.b    $00            ;Device Status Byte
  394. blk_low        dc.b    $00            ;Block Count (Low)
  395. blk_mid        dc.b    $00            ;Block Count (Mid)
  396. blk_hi        dc.b    $00            ;Block Count (High)
  397. id_str_len    dc.b    $00            ;ID String Length
  398. id_str        dcb.b    16,$00        ;ID STring (16 Bytes)
  399. d_type        dc.b    $00            ;Device Type
  400. d_stype        dc.b    $00            ;Device Subtype
  401. d_version    dc.w    $00            ;Version Word
  402.  
  403. ;*******************************************************
  404. ;
  405. ;    CODE SAMPLE #3
  406. ;
  407. ;    This code segment issues an Apple Scanner SEND
  408. ;    Command by using the Apple SCSI Card Generic SCSI
  409. ;    call ($2B).  By so doing we can send our halftone
  410. ;    filter to the Scanner.
  411. ;
  412. ;*******************************************************
  413.  
  414. htone_filter
  415.                                 ;
  416.                                 ; Issue the Call
  417.                                 ;
  418.             lda        scan_dnum
  419.             sta        dev_num3
  420.  
  421.             jsr        call_card
  422.             dc.b    $04            ;Control Call Command Number
  423.             dc.w    cmd_list3
  424.             rts
  425.  
  426. ;*******************************************************
  427.  
  428. cmd_list3    dc.b    $03            ;PCount = 3
  429. dev_num3    dc.b    $04            ;Device number
  430.             dc.w    filter_data    ;Pointer to data
  431.             dc.b    $2B            ;Control Code
  432.  
  433. ;*******************************************************
  434.  
  435. filter_data                        ;Our Data
  436.             dc.w    24            ;Total Length of Parms
  437.             dc.l    send_fltr    ;CDB Pointer (Long)
  438.             dc.l    DCData3        ;DCMove Ptr (Long)
  439.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  440.             dc.b    $00            ;Reserved
  441.             dc.b    $00            ;SCSI Status
  442.             dc.b    $00            ;Command Count
  443.             dc.l    $00000011    ;Trans Count (Long)
  444.             dc.b    $00            ;DMA Mode
  445.             dc.l    $00000000    ;Reserved (Long)
  446.  
  447. ;*******************************************************
  448.  
  449. send_fltr    dc.b    $2A            ;Scanner SEND Command
  450.             dc.b    $00            ;Reserved
  451.             dc.b    $02            ;Transfer Type
  452.             dc.b    $00            ;Reserved
  453.             dc.b    $00            ;Reserved
  454.             dc.b    $02            ;Transfer ID Byte
  455.             dc.b    $00            ;Reserved
  456.             dc.b    $00            ;Transfer Length (High)
  457.             dc.b    $11            ;Transfer Length (Low)
  458.             dc.b    $00            ;Reserved
  459.  
  460. ;*******************************************************
  461.  
  462. DCData3        dc.l    send_data    ;Scanner SEND Data Ptr
  463.             dc.l    $00000011    ;Transfer Count
  464.             dc.l    $00000000    ;Offset
  465.             dc.l    $00000000    ;Reserved
  466.  
  467.             dc.l    $00000000    ;DCStop
  468.             dc.l    $00000000    ;Reserved
  469.             dc.l    $00000000    ;Reserved
  470.             dc.l    $00000000    ;Reserved
  471.  
  472. ;*******************************************************
  473.  
  474. send_data    dc.b    $44            ;4 X 4 Matrix Size
  475.             dc.b    $08            ;Pel 0
  476.             dc.b    $88            ;Pel 1
  477.             dc.b    $28            ;Pel 2
  478.             dc.b    $A8            ;Pel 3
  479.             dc.b    $C8            ;Pel 4
  480.             dc.b    $48            ;Pel 5
  481.             dc.b    $E8            ;Pel 6
  482.             dc.b    $68            ;Pel 7
  483.             dc.b    $38            ;Pel 8
  484.             dc.b    $B8            ;Pel 9
  485.             dc.b    $18            ;Pel 10
  486.             dc.b    $98            ;Pel 11
  487.             dc.b    $F8            ;Pel 12
  488.             dc.b    $78            ;Pel 13
  489.             dc.b    $D8            ;Pel 14
  490.             dc.b    $58            ;Pel 15
  491.  
  492. ;*******************************************************
  493. ;
  494. ;    CODE SAMPLE #4
  495. ;
  496. ;    This code segment issues an Apple Scanner Define
  497. ;    Window Parameters Command by using the Apple SCSI
  498. ;    Card Generic SCSI call ($2B).  This command defines
  499. ;    the area of the scanner glass we want to scan
  500. ;
  501. ;*******************************************************
  502.  
  503. def_window
  504.                                 ;
  505.                                 ; Issue the Call
  506.                                 ;
  507.             lda        scan_dnum
  508.             sta        dev_num4
  509.  
  510.             jsr        call_card
  511.             dc.b    $04            ;Control Call Command Number
  512.             dc.w    cmd_list4
  513.             rts
  514.  
  515. ;*******************************************************
  516.  
  517. cmd_list4    dc.b    $03            ;PCount = 3
  518. dev_num4    dc.b    $00            ;Device number
  519.             dc.w    def_wndo    ;Pointer to data
  520.             dc.b    $2B            ;Control Code
  521.  
  522. ;*******************************************************
  523.  
  524. def_wndo                        ;Our Data
  525.             dc.w    24            ;Total Length of Parms
  526.             dc.l    def_wnd_cmd    ;CDB Pointer (Long)
  527.             dc.l    DCData4        ;DCMove Ptr (Long)
  528.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  529.             dc.b    $00            ;Reserved
  530.             dc.b    $00            ;SCSI Status
  531.             dc.b    $00            ;Command Count
  532.             dc.l    8+40        ;Trans Count (Long)
  533.             dc.b    $00            ;DMA Mode
  534.             dc.l    $00000000    ;Reserved (Long)
  535.  
  536. ;*******************************************************
  537.  
  538. def_wnd_cmd    dc.b    $24            ;Scanner Define Window
  539.                                 ;Parameters Command
  540.             dc.b    $00            ;Reserved
  541.             dc.b    $00            ;Reserved
  542.             dc.b    $00            ;Reserved
  543.             dc.b    $00            ;Reserved
  544.             dc.b    $00            ;Reserved
  545.             dc.b    $00            ;Transfer Length (High)
  546.             dc.b    $00            ;Transfer Length (Mid)
  547.             dc.b    8+40        ;Transfer Length (Low)
  548.             dc.b    $80            ;Apple Bit
  549.  
  550. ;*******************************************************
  551.  
  552. DCData4        dc.l    wndo_data    ;Scanner Window Data Ptr
  553.             dc.l    8+40        ;Transfer Count
  554.             dc.l    $00000000    ;Offset
  555.             dc.l    $00000000    ;Reserved
  556.  
  557.             dc.l    $00000000    ;DCStop
  558.             dc.l    $00000000    ;Reserved
  559.             dc.l    $00000000    ;Reserved
  560.             dc.l    $00000000    ;Reserved
  561.  
  562. ;*******************************************************
  563. ;    NOTE:  Remember that all values that are longer than
  564. ;    1 byte are in reversed order from natice 65xxx code.
  565. ;*******************************************************
  566.  
  567. wndo_data    dcb.b    6,$00        ;Reserved
  568.             dc.b    $00            ;Transfer Length (High)
  569.             dc.b    40            ;Transfer Length (Low)
  570.  
  571.             dc.b    $01            ;Window Identifier
  572.             dc.b    $00            ;Reserved
  573.  
  574.             dc.b    $00            ;X Resolution (High)
  575.             dc.b    150            ;X Resolution (Low)
  576.  
  577.             dc.b    $00            ;Y Resolution (High)
  578.             dc.b    75            ;Y Resolution (Low)
  579.                                 ;
  580.                                 ; We will use the corner as
  581.                                 ; Our Upper Left Possition.
  582.                                 ; This is at coordinate 0,0
  583.                                 ;
  584.             dc.b    $00            ;Upper Left X (High)
  585.             dc.b    $00            ;Upper Left X (Mid High)
  586.             dc.b    $00            ;Upper Left X (Mid Low)
  587.             dc.b    $00            ;Upper Left X (Low)
  588.  
  589.             dc.b    $00            ;Upper Left Y (High)
  590.             dc.b    $00            ;Upper Left Y (Mid High)
  591.             dc.b    $00            ;Upper Left Y (Mid Low)
  592.             dc.b    $00            ;Upper Left Y (Low)
  593.                                 ;
  594.                                 ; Width is defined as the number
  595.                                 ; of 1/1200-inch increments on
  596.                                 ; the horizontal axis; must be on
  597.                                 ; a byte boundry for both the
  598.                                 ; start and end points.  We will
  599.                                 ; set for 4 Inches and drop the
  600.                                 ; extra.
  601.                                 ; 
  602.             dc.b    $00            ;Width (High)
  603.             dc.b    $00            ;Width (Mid High)
  604.             dc.b    4*1200/256    ;Width (Mid Low)
  605.             dc.b    4*1200        ;Width (Low)
  606.                                 ;
  607.                                 ; Length is defined as the number
  608.                                 ; of 1/1200-inch increments on the
  609.                                 ; vertical axis.  We want ≈ 2 1/2
  610.                                 ; inches or 3072 increments
  611.                                 ; 
  612.             dc.b    $00            ;Length (High)
  613.             dc.b    $00            ;Length (Mid High)
  614.             dc.b    3072/256    ;Length (Mid Low)
  615.             dc.b    3072        ;Length (Low)
  616.  
  617.             dc.b    $80            ;Median Brightness
  618.             dc.b    $80            ;Median Threshold
  619.             dc.b    $80            ;Median Contrast
  620.  
  621.             dc.b    $01            ;Image Composition (Halftone)
  622.             dc.b    $01            ;Bits per Pixel
  623.  
  624.             dc.b    $00            ;Halftone Mask Always $00 (High)
  625.             dc.b    $02            ;Downloaded Mask Pattern (Low)
  626.  
  627.             dc.b    $03            ;Padding Type
  628.             dcb.b    2,$00        ;Reserved
  629.             dc.b    $00            ;Compression Type (None)
  630.             dcb.b    7,$00        ;Scanner Ref. is wrong.  Says 5.
  631.  
  632. ;*******************************************************
  633. ;
  634. ;    CODE SAMPLE #5
  635. ;
  636. ;    This code segment issues an Apple Scanner SCAN
  637. ;    Command by using the Apple SCSI Card Generic SCSI
  638. ;    call ($2B).  This starts the actual scanning.
  639. ;
  640. ;*******************************************************
  641.  
  642. start_scan
  643.                                 ;
  644.                                 ; Issue the Call
  645.                                 ;
  646.             lda        scan_dnum
  647.             sta        dev_num5
  648.  
  649.             jsr        call_card
  650.             dc.b    $04            ;Control Call Command Number
  651.             dc.w    cmd_list5
  652.             rts
  653.  
  654. ;*******************************************************
  655.  
  656. cmd_list5    dc.b    $03            ;PCount = 3
  657. dev_num5    dc.b    $00            ;Device number
  658.             dc.w    scan_cmd    ;Pointer to data
  659.             dc.b    $2B            ;Control Code
  660.  
  661. ;*******************************************************
  662.  
  663. scan_cmd                        ;Our Data
  664.             dc.w    24            ;Total Length of Parms
  665.             dc.l    do_scan        ;CDB Pointer (Long)
  666.             dc.l    DCData5        ;DCMove Ptr (Long)
  667.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  668.             dc.b    $00            ;Reserved
  669.             dc.b    $00            ;SCSI Status
  670.             dc.b    $00            ;Command Count
  671.             dc.l    $00000001    ;Trans Count (Long)
  672.             dc.b    $00            ;DMA Mode
  673.             dc.l    $00000000    ;Reserved (Long)
  674.  
  675. ;*******************************************************
  676.  
  677. do_scan        dc.b    $1B            ;SCAN
  678.                                 ;Parameters Command
  679.             dcb.b    3,$00        ;Reserved
  680.             dc.b    1            ;Transfer Length (Low)
  681.             dc.b    $00            ;Wait and Home Bits = 0
  682.  
  683. ;*******************************************************
  684.  
  685. DCData5        dc.l    window_ID    ;Scanner Window Data Ptr
  686.             dc.l    1            ;Transfer Count
  687.             dc.l    $00000000    ;Offset
  688.             dc.l    $00000000    ;Reserved
  689.  
  690.             dc.l    $00000000    ;DCStop
  691.             dc.l    $00000000    ;Reserved
  692.             dc.l    $00000000    ;Reserved
  693.             dc.l    $00000000    ;Reserved
  694.  
  695. ;*******************************************************
  696.  
  697. window_ID    dc.b    $01            ;Window Identifier
  698.  
  699. ;*******************************************************
  700. ;
  701. ;    CODE SAMPLE #6
  702. ;
  703. ;    This code segment issues a series of calls to the
  704. ;    Apple Scanner by using the Apple SCSI Card Generic
  705. ;    SCSI call ($2B).  We first issue a GET DATA STATUS
  706. ;    to see if there is enough data.  Then we read in a
  707. ;    single Scan Line with a READ Call.  The data is then
  708. ;    converted and placed in a video buffer.
  709. ;
  710. ;*******************************************************
  711.  
  712. get_data
  713.             stz        scan_line    ;Init the scanline to 0
  714.                                 ;
  715.                                 ; Issue the Call
  716.                                 ;
  717.             lda        scan_dnum
  718.             sta        dev_num6
  719.             sta        dev_num65
  720.  
  721. @get_data2    jsr        call_card
  722.             dc.b    $04            ;Control Call Command Number
  723.             dc.w    cmd_list6
  724.             bcs        @out
  725.                                 ;
  726.                                 ; Is there enough Data?
  727.                                 ; Enough data = 1 scan
  728.                                 ; line of 4 inches at 150
  729.                                 ; DPI or 600 pixels.  At
  730.                                 ; 8 pixels per byte, the
  731.                                 ; data will be padded to
  732.                                 ; 75 bytes.
  733.                                 ;
  734.             lda        scan_data
  735.             bne        @have_line
  736.             lda        scan_data+1
  737.             bne        @have_line
  738.             lda        scan_data+2
  739.             cmp        #rqst_cnt
  740.             blt        @get_data2
  741.                                 ;
  742.                                 ; We have the data.  Read
  743.                                 ; it.
  744.                                 ;
  745. @have_line    jsr        call_card
  746.             dc.b    $04            ;Control Call Command Number
  747.             dc.w    cmd_list65
  748.             bcs        @out
  749.                                 ;
  750.                                 ; Now we need to invert
  751.                                 ; the data.
  752.                                 ;
  753.             lda        #80            ;40 bytes/line
  754.             sta        byte_count
  755.             stz        byte_index
  756. @loop_1        lda        #$07
  757.             sta        seven        ;Pixels/byte
  758. @loop_2        ldx        #rqst_cnt-2
  759.             asl        raw_image+\
  760.                     rqst_cnt-1    ;Shift bits out the top to
  761. @loop_3        rol        raw_image,x    ;the next byte 1 at a time
  762.             dex
  763.             bpl        @loop_3
  764.             ldx        byte_index    ;Shift the last bit in to
  765.             ror        screen,x    ;this byte.  This reverses the
  766.             dec        seven        ;bit ordering. Also taking 8
  767.             bne        @loop_2        ;bits per byte down to 7
  768.             lsr        screen,x
  769.             inc        byte_index
  770.             dec        byte_count
  771.             bne        @loop_1
  772.                                 ;
  773.                                 ; Move data to Scan Line
  774.                                 ;
  775.             ldx        scan_line
  776.             jsr        on_screen
  777.             inc        scan_line
  778.             bra        @get_data2
  779.  
  780. @out        lda        #$00
  781.             clc
  782.             rts
  783.  
  784. ;*******************************************************
  785.  
  786. scan_line    dc.b    $00            ;Scan Line Index
  787. byte_count    dc.b    $00            ;Number of bytes left
  788. byte_index    dc.b    $00            ;Current Byte in use
  789. seven        dc.b    $00            ;Count off 7 pixels
  790. screen        dcb.b    80,0        ;Place to do the screen
  791.  
  792. ;*******************************************************
  793.  
  794. cmd_list6    dc.b    $03            ;PCount = 3
  795. dev_num6    dc.b    $00            ;Device number
  796.             dc.w    gd_status    ;Pointer to data
  797.             dc.b    $2B            ;Control Code
  798.  
  799. cmd_list65    dc.b    $03            ;PCount = 3
  800. dev_num65    dc.b    $00            ;Device number
  801.             dc.w    read        ;Pointer to data
  802.             dc.b    $2B            ;Control Code
  803.  
  804. ;*******************************************************
  805.  
  806. gd_status                        ;Our Data
  807.             dc.w    24            ;Total Length of Parms
  808.             dc.l    get_stat    ;CDB Pointer (Long)
  809.             dc.l    DCData6        ;DCMove Ptr (Long)
  810.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  811.             dc.b    $00            ;Reserved
  812.             dc.b    $00            ;SCSI Status
  813.             dc.b    $00            ;Command Count
  814.             dc.l    $0000000C    ;Trans Count (Long)
  815.             dc.b    $00            ;DMA Mode
  816.             dc.l    $00000000    ;Reserved (Long)
  817.  
  818. read                            ;Our Data
  819.             dc.w    24            ;Total Length of Parms
  820.             dc.l    get_data2    ;CDB Pointer (Long)
  821.             dc.l    DCData65    ;DCMove Ptr (Long)
  822.             dc.l    $00000000    ;Rqst Sense Ptr (Long)
  823.             dc.b    $00            ;Reserved
  824.             dc.b    $00            ;SCSI Status
  825.             dc.b    $00            ;Command Count
  826.             dc.l    rqst_cnt    ;Trans Count (Long)
  827.             dc.b    $00            ;DMA Mode
  828.             dc.l    $00000000    ;Reserved (Long)
  829.  
  830. ;*******************************************************
  831.  
  832. get_stat    dc.b    $34            ;GET DATA STATUS
  833.                                 ;Parameters Command
  834.             dcb.b    7,$00        ;Reserved
  835.             dc.b    12            ;Transfer Length (Low)
  836.             dc.b    $00            ;Wait and Home Bits = 0
  837.  
  838. get_data2    dc.b    $28            ;READ
  839.                                 ;Parameters Command
  840.             dcb.b    4,$00        ;Reserved
  841.             dc.b    $01            ;Window ID
  842.             dc.b    $00            ;Transfer Length (High)
  843.             dc.b    $00            ;Transfer Length (Mid)
  844.             dc.b    rqst_cnt    ;Transfer Length (Low)
  845.             dc.b    $00            ;Wait and Home Bits = 0
  846.  
  847. ;*******************************************************
  848.  
  849. DCData6        dc.l    data_cnt    ;Data Pointer
  850.             dc.l    12            ;Transfer Count
  851.             dc.l    $00000000    ;Offset
  852.             dc.l    $00000000    ;Reserved
  853.  
  854.             dc.l    $00000000    ;DCStop
  855.             dc.l    $00000000    ;Reserved
  856.             dc.l    $00000000    ;Reserved
  857.             dc.l    $00000000    ;Reserved
  858.  
  859. DCData65    dc.l    raw_image    ;Data Pointer
  860.             dc.l    rqst_cnt    ;Transfer Count
  861.             dc.l    $00000000    ;Offset
  862.             dc.l    $00000000    ;Reserved
  863.  
  864.             dc.l    $00000000    ;DCStop
  865.             dc.l    $00000000    ;Reserved
  866.             dc.l    $00000000    ;Reserved
  867.             dc.l    $00000000    ;Reserved
  868.  
  869. ;*******************************************************
  870.  
  871. data_cnt                        ;Data Space
  872.             dcb.b    2,$00        ;Reserved
  873.             dc.b    $00            ;Data Length
  874.             dc.b    $00            ;Block
  875.             dc.b    $00            ;Window Identifier
  876.             dcb.b    4,$00        ;Reserved
  877. scan_data    dc.b    $00            ;Scan Data (High)
  878.             dc.b    $00            ;Scan Data (Mid)
  879.             dc.b    $00            ;Scan Data (Low)
  880.  
  881. raw_image    dcb.b    100,$00;Scanned Data Image
  882.  
  883. ;*******************************************************
  884.  
  885. on_screen    lda        scan_tbl_lo,x
  886.             sta        <My_ZPage
  887.             lda        scan_tbl_hi,x
  888.             sta        <My_ZPage+1
  889.                                 ;
  890.                                 ; Do Main Bank Screen
  891.                                 ;
  892.             sta        SET80COL    ;Allow writes to AUX 48k
  893.  
  894.             sta        WRMAINRAM    ;Write to Main 48k
  895.  
  896.             ldx        #80-1
  897.             ldy        #40-1
  898. @loop        lda        screen,x
  899.             eor        #$7f
  900.             sta        (My_ZPage),y
  901.             dex
  902.             dex
  903.             dey
  904.             bpl        @loop
  905.                                 ;
  906.                                 ; Do Aux Bank Screen
  907.                                 ;
  908.             sta        WRCARDRAM    ;Write to Alternate 48k
  909.  
  910.             ldx        #80-2
  911.             ldy        #40-1
  912. @loop2        lda        screen,x
  913.             eor        #$7f
  914.             sta        (My_ZPage),y
  915.             dex
  916.             dex
  917.             dey
  918.             bpl        @loop2
  919.  
  920.             sta        WRMAINRAM    ;Write to Main 48k
  921.  
  922.             sta        CLR80COL    ;Disallow writes to AUX 48k
  923.  
  924.             clc
  925.             rts
  926.  
  927. scan_tbl_lo    dcb.b    8,$00        ;Lines 0-7
  928.             dcb.b    8,$80        ;Lines 8-15
  929.             dcb.b    8,$00        ;Lines 16-23
  930.             dcb.b    8,$80        ;Lines 24-31
  931.             dcb.b    8,$00        ;Lines 32-39
  932.             dcb.b    8,$80        ;Lines 40-47
  933.             dcb.b    8,$00        ;Lines 48-55
  934.             dcb.b    8,$80        ;Lines 56-63
  935.  
  936.             dcb.b    8,$28        ;Lines 64-71
  937.             dcb.b    8,$a8        ;Lines 72-79
  938.             dcb.b    8,$28        ;Lines 80-87
  939.             dcb.b    8,$a8        ;Lines 88-95
  940.             dcb.b    8,$28        ;Lines 96-103
  941.             dcb.b    8,$a8        ;Lines 104-111
  942.             dcb.b    8,$28        ;Lines 112-119
  943.             dcb.b    8,$a8        ;Lines 120-127
  944.  
  945.             dcb.b    8,$50        ;Lines 128-135
  946.             dcb.b    8,$d0        ;Lines 136-143
  947.             dcb.b    8,$50        ;Lines 144-151
  948.             dcb.b    8,$d0        ;Lines 152-159
  949.             dcb.b    8,$50        ;Lines 160-167
  950.             dcb.b    8,$d0        ;Lines 168-175
  951.             dcb.b    8,$50        ;Lines 176-183
  952.             dcb.b    8,$d0        ;Lines 184-191
  953.  
  954. scan_tbl_hi    dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  955.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  956.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  957.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  958.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  959.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  960.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  961.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  962.  
  963.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  964.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  965.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  966.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  967.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  968.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  969.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  970.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  971.  
  972.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  973.             dc.b    $20,$24,$28,$2c,$30,$34,$38,$3c
  974.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  975.             dc.b    $21,$25,$29,$2d,$31,$35,$39,$3d
  976.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  977.             dc.b    $22,$26,$2a,$2e,$32,$36,$3a,$3e
  978.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  979.             dc.b    $23,$27,$2b,$2f,$33,$37,$3b,$3f
  980.  
  981. ;*******************************************************
  982. ;
  983. ;    CODE SAMPLE #7
  984. ;
  985. ;    This code segment toggles the HiRes Soft switches so
  986. ;    that we can see what was just scanned.
  987. ;
  988. ;*******************************************************
  989.  
  990. display
  991.                                 ;
  992.                                 ; Save the Current State
  993.                                 ;
  994.             lda        RDTEXT
  995.             sta        @text        ;Text/Graphics
  996.  
  997.             lda        RDMIX
  998.             sta        @mixed        ;Mixed?
  999.  
  1000.             lda        RDPAGE2
  1001.             sta        @page        ;Page 1 or 2
  1002.  
  1003.             lda        RDHIRES
  1004.             sta        @hires        ;HiRes Mode?
  1005.  
  1006.             lda        RD80VID
  1007.             sta        @80col        ;80-Column Mode?
  1008.  
  1009.             sta        SET80VID    ;40-Column Mode.
  1010.             sta        TXTCLR        ;Standard Apple II Graphics
  1011.             sta        MIXCLR        ;Clear Mixed Mode
  1012.             sta        TXTPAGE1    ;Page 1
  1013.             sta        HIRES        ;HiRes Mode
  1014.             sta        CLRAN3        ;Clear annunciator 3
  1015.  
  1016.             sta        KBD_STRB    ;Clear Key Strobe
  1017. @key_loop    lda        KBD            ;Get key
  1018.             bpl        @key_loop    ;Wait for Key Press
  1019.             sta        KBD_STRB    ;Clear Key Strobe
  1020.             cmp        #ESC        ;ESC Key
  1021.             clc
  1022.             bne        @chk_txt
  1023.             sec                    ;Exit on ESC
  1024.  
  1025.             lda        SETAN3        ;Set annunciator 3
  1026.  
  1027. @chk_txt    lda        @text
  1028.             bpl        @chk_mix
  1029.             sta        TXTSET        ;Text on
  1030.  
  1031. @chk_mix    lda        @mixed
  1032.             bpl        @chk_page
  1033.             sta        MIXSET        ;Mixed on
  1034.  
  1035. @chk_page    lda        @page
  1036.             bpl        @chk_hires
  1037.             sta        TXTPAGE2    ;Page 2
  1038.  
  1039. @chk_hires    lda        @hires
  1040.             bmi        @chk_40col
  1041.             sta        LORES        ;HiRes Off
  1042.  
  1043. @chk_40col    lda        @80col
  1044.             bmi        @rts
  1045.             sta        CLR80VID    ;80-Column on.
  1046.  
  1047. @rts        rts
  1048.  
  1049. @text        dc.b    $00
  1050. @mixed        dc.b    $00
  1051. @page        dc.b    $00
  1052. @hires        dc.b    $00
  1053. @80col        dc.b    $00
  1054.  
  1055. ;*******************************************************
  1056.  
  1057.             ENDP
  1058.             
  1059.             END
  1060.  
  1061.